import Vue from 'vue'
import VueRouter from 'vue-router'

import Home from '@/views/home/Home'
import Seach from '@/views/seach/Seach'
import Login from '@/views/login/Login'
import Registered from '@/views/registered/Registered'
import HomeMain from '@/views/main/HomeMain'
//使用router
Vue.use(VueRouter)

const routes = [
  {
    path: '',
    redirect: '/home'
  },
  {
    path: '/home/',
    component: Home,
    meta:{show:true},
    //二级子路由
    children: [
      {
        //搜索
        path: "seach/ :keyword?",
        component: Seach,
        name: "seach",
        meta:{show:true}
      },
      {
        //登录
        path: '/login',
        component: Login,
        //元信息判断当前组件是否显示，为true显示，为false则不显示，路由上添加v-show判断
        meta: {show:false}
      },
      {
        //注册
        path: '/registered',
        component: Registered,
        meta:{show:false}
      },
      {
        //首页
        path: '/home',
        component: HomeMain,
        meta:{show:true}
      }
    ]
  },
  
]

const router = new VueRouter({
  base: '/dist',//基础路径
  mode: 'history',
  routes
});
//重写push方法，防止重复报错
const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (to) {
  return VueRouterPush.call(this, to).catch(err => err)
}


export default router;
